<template>
  <div class="serverDeploy custom-checkbox">
    <basic-container>
      <avue-crud
        ref="crud"
        :page.sync="page"
        :data="tableData"
        :table-loading="tableLoading"
        :option="tableOption"
        :permission="permissionList"
        @on-load="getList"
        @search-change="searchChange"
        @refresh-change="refreshChange"
        @size-change="sizeChange"
        @current-change="currentChange"
        @row-del="rowDel"
		@row-click="handleRowClick"
        @select="handleRowClick"
      >
        <template slot="menuLeft">
			<el-button type="primary" size="small" icon="el-icon-plus" @click="handleCreate">新增</el-button>
			<el-button type="primary" size="small" icon="el-icon-download">导出</el-button>
			<el-button size="small" icon="el-icon-refresh" type="primary" @click="handleCreate">系统还原</el-button>
			<el-button size="small" icon="el-icon-refresh-left" type="primary" @click="rowDel()">状态查询</el-button>
			<el-button size="small" icon="el-icon-video-play" type="primary" @click="handleCreate">启动</el-button>
			<el-button size="small" icon="el-icon-video-pause" type="primary" @click="handleCreate">停止</el-button>
			<el-button size="small" icon="el-icon-upload" type="primary" @click="oneClick()">一键部署</el-button>
        </template>
        <template slot-scope="scope" slot="menu">
			<el-button size="small" icon="el-icon-document" type="text" @click="handleCreate">编辑</el-button>
			<el-button
				size="small"
				icon="el-icon-delete"
				type="text"
				@click="rowDel(scope.row,scope.index)"
			>删除</el-button>
        </template>
      </avue-crud>
    </basic-container>
    <deploy-add ref="deployAdd"></deploy-add>
	<deploy-one ref="deployOne"></deploy-one>
  </div>
</template>

<script>
import { delObj, fetchList } from "~/admin/api/log";
import { tableOption } from "~/admin/const/mocha-itom/deploy-management";
import { mapGetters } from "vuex";
import deployAdd from "./modules/deploy-add";
import deployOne from "./modules/deploy-one";
import tableCheckbox from "~/assets/vue-mixin/table-checkbox"
export default {
  name: "deployManagement",
  mixins: [tableCheckbox],
  data() {
    return {
      tableData: [],
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 10 // 每页显示多少条
      },
      tableLoading: false,
      tableOption: tableOption,
      form: {}
    };
  },
  components: {
	deployAdd,
	deployOne
  },
  computed: {
    ...mapGetters(["permissions"]),
    permissionList() {
      return {
        delBtn: this.vaildData(this.permissions.sys_log_del, false)
      };
    }
  },
  methods: {
    getList(page, params) {
      this.tableLoading = true;
      fetchList(
        Object.assign(
          {
            descs: "create_time",
            current: page.currentPage,
            size: page.pageSize
          },
          params,
          this.form
        )
      ).then(response => {
        this.tableData = response.data.data.records;
        this.page.total = response.data.data.total;
        this.tableLoading = false;
      });
    },
    rowDel: function(row, index) {
      this.$confirm('是否确认删除ID为"' + row.id + '"的日志?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(function() {
          return delObj(row.id);
        })
        .then(data => {
          this.getList(this.page);
          this.$message.success("删除成功");
        });
    },
    handleCreate() {
      this.$refs.deployAdd.init();
	},
	oneClick(){
		this.$refs.deployOne.init();

	},
    searchChange(form, done) {
      this.form = form;
      this.getList(this.page, form);
      done();
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    currentChange(current) {
      this.page.currentPage = current;
    },
    refreshChange() {
      this.getList(this.page);
    }
  }
};
</script>
